import 'package:car_music/src/commont/button.dart';
import 'package:car_music/src/commont/unit_bar.dart';
import 'package:flutter/material.dart';
import 'package:flutter_kit_dsp/flutter_kit_dsp.dart';

class ChGroupView extends GetxGlobalView {
  final String title;
  final List<GroupModel> groupList;
  const ChGroupView({super.key, required this.title, required this.groupList});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.spaceAround,
      spacing: 5,
      children: [
        Flexible(child: UnitBar(title: title, groupList: groupList)),
        Flexible(
          child: Obx(() {
            // final list = controller.rxModel.value.ch_list;
            // final grouplist = List.generate((list.length / 2).toInt(), (index) {
            //   final model = GroupModel(ch1: list[2 * index], ch2: list[2 * index + 1]);
            //   model.select = model.ch1!.select && model.ch2!.select;
            //   return model;
            // });
            return Row(
                // mainAxisAlignment: MainAxisAlignment.center,
                spacing: 10,
                children: controller.rxModel.value.ch_list.map(($0) {
                  GroupModel group =
                      groupList.firstWhereOrNull((g) => (g.ch1?.num ?? 0) == $0.num || (g.ch2?.num ?? 0) == $0.num)!;
                  return Expanded(
                      child: kMyTextButton(
                    name: $0.name,
                    select: $0.select,
                    onClick: (value) {
                      globalController.chooseChInGroup(groupList, group, $0, title);
                    },
                  ));
                }).toList());
          }),
        ),
      ],
    );
  }
}
